import 'dart:isolate';

void main(List<String> args) {
  print("starting");
  final receivePort = new ReceivePort();
  Isolate.spawn(computeAdd, {'n': 10000000, 'sendPort': receivePort.sendPort});
  receivePort.listen((result) {
    print("计算结果: $result");
    receivePort.close();
  });
  print("ending");
}

void computeAdd(Map<String, dynamic> args) {
  final int n = args['n'];
  final sendPort = args['sendPort'] as SendPort;
  int result = 0;
  for (int i = 0; i < n; i++) result += i;
  sendPort.send(result);
  print("result:$result");
}
